using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace CollegeShop.Infrastructure.Entities.Repository
{
    [Table("T_Salaryreport")]
    public class T_Salaryreport : IEntity<T_Salaryreport>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(8)]
        public string Year { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(8)]
        public string Month { get; set; }

        [Column(TypeName="nvarchar")]
        [StringLength(128)]
        public string UserName { get; set; }

        public decimal BasicSalary { get; set; }

        public decimal SaledMoney { get; set; }

        public decimal RoyaltyRate { get; set; }

        public decimal OnTimeRate { get; set; }

        public decimal Bonus { get; set; }

        public decimal RealSalary { get; set; }

        public override T_Salaryreport Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.ID == id);
        }

        public override T_Salaryreport Find(System.Linq.Expressions.Expression<Func<T_Salaryreport, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Salaryreport.FirstOrDefault(where);
                if (item != null)
                {
                    this.ID = item.ID;
                    this.Year = item.Year;
                    this.Month = item.Month;
                    this.UserName = item.UserName;
                    this.BasicSalary = item.BasicSalary;
                    this.SaledMoney = item.SaledMoney;
                    this.RoyaltyRate = item.RoyaltyRate;
                    this.OnTimeRate = item.OnTimeRate;
                    this.Bonus = item.Bonus;
                    this.RealSalary = item.RealSalary;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_Salaryreport, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Salaryreport.Any(where);
            }
        }
    }
}
